I have array of POJO's targetsArray. I need to get it from java script in my page. I am trying to use Callback Parameters.
Bean code
Code: Select all
@ManagedBean(name = "TTAManagerBean")
@RequestScoped
public class TTAManagerBean {
public Object[] targetsArray;
public TTAManagerBean() {
super();
ArrayList<VTarget> targetsList = new ArrayList<VTarget>();
targetsList.add(new VTarget("Some target", 1.));
targetsList.add(new VTarget("Target", 0.6));
targetsArray = targetsList.toArray();
}
public void loadData(ActionEvent actionEvent) {
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.addCallbackParam("tararray", targetsArray);
}
}
public class VTarget implements Serializable {
private static final long serialVersionUID = 1L;
public String name;
public double priority;
public VTarget(String name, double priority) {
super();
this.name = name;
this.priority = priority;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPriority() {
return priority;
}
public void setPriority(double priority) {
this.priority = priority;
}
}
Code: Select all
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<ui:decorate template="../template/content.xhtml">
<ui:define name="body">
<p:panel id="tree" header="Tree">
<p:commandButton value="render" actionListener="#{TTAManagerBean.loadData}" oncomplete="render(xhr, status, args)"/>
<div id="portfolioTree" style="height: 600px;">
<script type="text/javascript">
function render(xhr, status, args){
var tararray = args.tararray;
alert(tararray.length);
for (target in tararray)
{
alert(target.name + " " + target.priority);
}
}
</script>
</div>
</p:panel>
</ui:define>
</ui:decorate>
</ui:composition>
when I press button I get messagebox with text "undefined" and nothing more happens. How can I solve this problem.
Thanks.