UIParameter cannot be a child of HTMLCommandButton, only of HtmlCommandLink
On 9/7/06, Michael Heinen <[EMAIL PROTECTED]> wrote:
Hi all,
I am desperately trying to create a custom DataScroller with
HTMLCommandButtons instead of HTMLCommandLinks.
The problem is that the corresponding ActionListener is never called when I
click the button.
The clientID is not found in the requestMap in the decode method of my
Renderer.
When I use HMTLCommandLinks instead of the buttons, everything works fine.
Basically I used the
org.apache.myfaces.custom.datascroller.HtmlDataScrollerRenderer
as master
and created a new method getCommandButton (instead of getLink).
protected HtmlCommandButton getCommandButton(FacesContext facesContext,
ListScroller scroller, String text, int pageIndex) {
String id = ListScrollerRenderer.PAGE_NAVIGATION +
Integer.toString(pageIndex);
Application application = facesContext.getApplication();
HtmlCommandButton button = (HtmlCommandButton)
application.createComponent(HtmlCommandButton.COMPONENT_TYPE);
button.setId(scroller.getId() + id);
//*** button.addActionListener( scroller.getActionListener() );
//should this work ??? ****
button.setTransient(true);
button.setType("submit");
button.setValue( text );
//Do I need a UIParameter for a HTMLCOmmandButton???
UIParameter parameter = (UIParameter)
application.createComponent(UIParameter.COMPONENT_TYPE);
parameter.setId(scroller.getId() + id + "_param");
parameter.setTransient(true);
parameter.setName(scroller.getClientId(facesContext));
parameter.setValue(id);
List children = button.getChildren();
children.add(parameter);
scroller.getChildren().add(button);
return button;
}
Following is the decode method.
The problem is that the var param is always null !
How can I check that my HtmlCommandButton has been clicked?
public void decode(FacesContext context, UIComponent component) {
if (component.isRendered()){
RendererUtils.checkParamValidity(context,
component, ListScroller.class);
Map parameter = context.getExternalContext().getRequestParameterMap();
String param = (String) parameter.get(component.getClientId(context));
if (param != null) {
if (param.startsWith(PAGE_NAVIGATION)){
// the user chose a specific page# to jump to
component.queueEvent(new ScrollerActionEvent(component,
Integer.parseInt(param.substring(PAGE_NAVIGATION.length(),
param.length()))));
}
else {
// the user chose
first/last/prev/next/fastrewind/fastforward
component.queueEvent(new ScrollerActionEvent(component,
param));
}
}
}
}
In the original getLink method is a UIParameter added an it's name is set to
scroller.getClientId.
This does not work with a HTMLCommandButton.
Any help is highly appreciated
Michael