This blog mainly contains technical stuff. It may contain info of some events too.
Friday, November 30, 2007
Final year project
I'm working on XML Encryption part in XMLSec project. I have to use Axiom instead of DOM to parse XML in this new version to increase performance as it uses pull parsing while DOM does push parsing.
We have to finish the project before end of January. So having a hard time:)
Wednesday, March 14, 2007
Training is over
Thursday, February 08, 2007
JSF: Binding dataTable from managed bean
<h:dataTable var="item" value="#{MyBean.items}"
binding="#{MyBean.dataTable}" >
<h:column>
<h:outputText styleClass="output" value="#{item.productName}"/>
</h:column>
<h:column>
<h:commandButton value="remove" action="#{MyBean.remove}" />
</h:column>
</h:dataTable>
.public class MyBean {
private ArrayList items = new ArrayList();
private HtmlDataTable dataTable;
public ArrayList getItems() {
return items;
}
public void setItems(List items) {
this.items = new ArrayList(items);
}
public void remove(){
ItemBean item = (ItemBean) getDataTable().getRowData();
items.remove(item);
}
public HtmlDataTable getDataTable() {
return dataTable;
}
public void setDataTable(HtmlDataTable dataTable){
this.dataTable = dataTable;
}
}
here, when user clicks the remove button, the related item is removedfrom the data table.
Wednesday, December 20, 2006
Calling Servlets from JSF
This is the bean which is called from .jsp page
import javax.faces.context.FacesContext;
public class ServletTest {
public void doThis(){
String url = "url of your servlet";
FacesContext context = FacesContext.getCurrentInstance();
try {
context.getExternalContext().dispatch(url);
}catch (Exception e) {
e.printStackTrace();
}
finally{
context.responseComplete();
}
}
}
This is the .jsp page
<f:view>
<h:form id="myForm">
<h:commandButton value="Do" action="#{ServletTest.doThis}" />
</h:form>
</f:view>
Saturday, December 02, 2006
Parameter passing in JSF
My part of the interns' project is to develop a web portal using JSF. However I'm new to JSF and have to search and learn. The hardest point I struggled with is passing parameters to the backing bean from the UI. I was stuck a whole day on this. Finally I got it and I'm wondering how hard this simple thing to be found and this is that.
<h:form>
<h:commandButton value="Show" actionListener="#{MyBean.setStr}" action="#{MyBean.go}" >
<f:attribute name="name" value="Hello"/>
</h:commandButton>
</h:form>
public class MyBean {
private String str;
.....
public void setStr(ActionEvent event){
String name = (String) event.getComponent().getAttributes().get("name");
this.str=name;
}
public String go(){
return ("success");
}
}
This may help those who are new to JSF like me:)