Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to create BINDING of command link with backing bean

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

How to create BINDING of command link with backing bean

Thanks
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
h:commandLink is an UICommand � HtmlCommandLink component. Check the API doc.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. A few days have passed since that advice was given. I am working with JSF and Java 1.6.0_14 using Netbeans 6.7.1. I am building my HtmlPanelGrid dynamically in the following way.

public void addItemNumbers(ValueChangeEvent changeEvent)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
Application application =
facesContext.getApplication();
List<UIComponent> children = itemPanel.getChildren();
children.clear();
srchDesc= "";
srchItemno = (String)changeEvent.getNewValue();
String[][] itemArray = getItemsByItemno( srchItemno);

HtmlCommandLink outputItemno;
UIParameter id;

for ( int count = 0; count < itemArray.length; count++)
{
// ID REQUIRED
id = new UIParameter();
id.setName("id" + itemArray[count][0]);
id.setValue( itemArray[count][0]);
// ITEM NUMBER
outputItemno = (HtmlCommandLink) application.createComponent( HtmlCommandLink.COMPONENT_TYPE);
outputItemno.setValue( itemArray[count][0]);
String action = "#{ itemcountbean.listSetup}";
MethodExpression methodExpression =
FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
createMethodExpression(FacesContext.getCurrentInstance().getELContext(), action, String.class,
new Class<?>[0]);
outputItemno.setActionExpression( methodExpression);
ValueExpression valueEx =
application.getExpressionFactory().createValueExpression(facesContext. getELContext(),
"#{itemcountbean.itemno}", String.class);
outputItemno.setValueExpression( itemArray[count][0], valueEx );
outputItemno.setStyle( "color: blue");
outputItemno.getChildren().add(id);
children.add( outputItemno);

// ITEM DESCRIPTION
HtmlOutputText outputItemDesc = (HtmlOutputText) application
.createComponent( HtmlOutputText.COMPONENT_TYPE);
outputItemDesc.setValue( itemArray[count][1]);
outputItemDesc.setStyle( "color: blue");
outputItemDesc.getChildren().add(id);
children.add( outputItemDesc);
}
logger.log( Level.FINER, "HtmlCommandLink item panel populated");
}


This is displayed by the JSP page with the following code:


<h:panelGrid id="itemPanel"
binding="#{ item.itemPanel}"
columns="2" border="1" cellspacing="5" />



The itemcountbean has the following coding in itemcountbean:

public String listSetup() {
logger.log( Level.INFO, "itemcountbean.listSetup");
logger.log( Level.INFO, "itemcountbean.itemno ["+this.itemno+"]");
...
return "itemcount_list";
}

Everything appears to be working except transferring via the 'binding' that is suppose to occur using the

ValueExpression valueEx =
application.getExpressionFactory().createValueExpression(facesContext. getELContext(),
"#{itemcountbean.itemno}", String.class);
outputItemno.setValueExpression( itemArray[count][0], valueEx );

part of the code.

And my
logger.log( Level.INFO, "itemcountbean.listSetup");
logger.log( Level.INFO, "itemcountbean.itemno ["+this.itemno+"]");

log returns

itemcountbean.listSetup
itemcountbean.itemno [null]

I have read through the JavaDocs to attempt to understand establishing the binding of ' #{itemcountbean.itemno} ' in the correct manner. I have searched dozens of sites trying to determine my error(s). Some advice was as little as 'Read the JavaDocs', but most was on binding before the JSF and/or NBs requiring use of the ValueExpression and setValueExpression. Most of the answers are 2-3 years old.

Would someone please help me in completion of binding/transferring my value from my HtmlCommandLink to be used in the backing bean?

Thank you.
rdb

 
Richard Blaha
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

OK. Here is what I found and what works. This is complete replacement code for what I presented in the previous post. This code is simpler and easier once I learned how to do it. I learned there is a huge difference between the introductory JSF code in chapter 1 and the Integrating of Data Grids in chapter 10 of JavaServerFaces In Action (Manning C 2005). Even in reading and using these examples (the first got me facing the problem I did and the second suggested I change my method) it still did not answer the question I needed answered. I ended up copying from a previous Visual ICEFaces project I had succesfully built. The final and key answer to my question I got from a blog I found searching for 'HtmlOutputText binding'. Passing component attributes from JSF to backing beans Again I have implemented all in the following replacement code.

itembean:

private String itemDataTableArray[][];


public void addItemNumbers(ValueChangeEvent changeEvent)
{
srchDesc= "";
srchItemno = (String)changeEvent.getNewValue();
itemDataTableArray = getItemsByItemno( srchItemno);
}

...

private HtmlDataTable itemDataTable = new HtmlDataTable();

public HtmlDataTable getItemDataTable() {
return itemDataTable;
}

public void setItemDataTable(HtmlDataTable hdt) {
this.itemDataTable = hdt;
}

private UIColumn column1 = new UIColumn();

public UIColumn getColumn1() {
return column1;
}

public void setColumn1(UIColumn uic) {
this.column1 = uic;
}
private UIColumn column2 = new UIColumn();

public UIColumn getColumn2() {
return column2;
}

public void setColumn2(UIColumn uic) {
this.column2 = uic;
}



This is displayed by the JSP page with the following code:


<h:dataTable id="itemDataTable" var="currentRow" styleClass="list_form" rowClasses="odd_row, even_row" border="1" cellspacing="5" binding="#{itembean.itemDataTable}" value="#{itembean.itemDataTableArray}">
<h:column binding="#{itembean.column1}" id="column1">
<f:facet name="header">
<h:outputText value="Item Number" />
</f:facet>
<h:commandLink action="#{itemcountbean.listSetup}">
<h:outputText id="outputText1" binding="#{itemcountbean.itemnoHtmlOutputText}" value="#{currentRow[0]}" >
<f:attribute name="itemText" value="#{currentRow[0]}" />
</h:outputText>
</h:commandLink>
</h:column>
<h:column binding="#{itembean.column2}" id="column2">
<f:facet name="header">
<h:outputText value="Item Desc" />
</f:facet>
<h:outputText id="outputText2" value="#{currentRow[1]}" />
</h:column>
</h:dataTable>



The itemcountbean has the following coding in itemcountbean:

private String item = null;
private HtmlOutputText itemHtmlOutputText;

...

/**
* @return the itemHtmlOutputText
*/
public HtmlOutputText getItemHtmlOutputText() {
return itemHtmlOutputText;
}

/**
* @return the itemHtmlOutputText
*/
public String getItemHtmlOutputTextValue() {
return (String) itemHtmlOutputText.getAttributes().get("itemText");
}

/**
* @param itemHtmlOutputText the itemHtmlOutputText to set
*/
public void setitemHtmlOutputText(HtmlOutputText itemHtmlOutputText) {
this.itemHtmlOutputText = itemHtmlOutputText;
}


// Setup methods
public String listSetup() {
item = getItemHtmlOutputTextValue();
return "itemcount_itemlist";
}





 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic