1:rich:suggestionbox,
这个控件主要是类似百度的索引方法,当你移动或者onchange时,会触发查询事件;
下面代码的例子:
</h:panelGroup>
JAVA 代码:
private List<MdBin> autocompete = new ArrayList<MdBin>();
public List<MdBin> getAutocompete() {
return autocompete;
}
public void setAutocompete(List<MdBin> autocompete) {
this.autocompete = autocompete;
}
public List<MdBin> autocompete(Object prefix) {
String pref = (String) prefix;
List<MdBin> result = new ArrayList<MdBin>();
Iterator<MdBin> iterator = autocompete.iterator();
while (iterator.hasNext()) {
MdBin elem = iterator.next();
if ((elem.getCode() != null && elem.getCode().toLowerCase().indexOf(pref.toLowerCase()) == 0) || "".equals(pref)) {
result.add(elem);
}
}
logger.debug("result" + result.size());
return result;
}
public void findBinNumber() {
logger.debug("-------:" + this.searchVO.getBinNumer());
onchangeToSelect();
}
public void onchangeToSelect() {
logger.debug("automatically to search");
if (searchVO.getMdItemAttribute().getMdCompany().getAid() != null
&& searchVO.getMdItemAttribute().getMdItem().getAid() != null
&& searchVO.getMdWarehouseLocation().getAid() != null) {
logger.debug("automatically to search");
statusMessages = (StatusMessages) Component.getInstance(StatusMessages.COMPONENT_NAME, true);
autocompete = service.findAllBin(searchVO.getMdItemAttribute().getMdCompany().getAid(), searchVO
.getMdWarehouseLocation().getAid());
search();
}
}
可以看到,suggestionAction是我们查询的所有数据,我们是用for进行遍历,当Onselect的时候,触发jsFunction,取得List 值,从而渲染bin,最后调用seearch方法;
第二个richfaces控件:A4j:region
主要是改变状态,直到执行完毕后,Start只是点击时的突变显示,运行后后显示stop
<a4j:region id="rb">
<a4j:status id="commonstatus" for="rb">
<f:facet name="start">
<h:graphicImage value="/img/icon/running.png" />
</f:facet>
<f:facet name="stop">
<h:graphicImage url="/img/icon/initial.png"
rendered="#{(_detail.mdMonthEndTask.mdMonthEndTaskAction.checkPosition == 'M' ? 'true':'false') and (_detail.mdMonthEndExecution.manualCheckStatus =='I' ? 'true' : 'false')}" />
</f:facet>
</a4j:status>
</a4j:region>
第三个:ListShuttle:
这个方法主要是移动左右的选择,封装Add,Remove,AddALL ,Remove ALL
代码:
<rich:panel>
<a:region>
<h:panelGrid columns="2" id="binNoPanel">
<rich:listShuttle id="listBinNo" sourceValue="#{binVsItemAction.availableBin}" targetValue="#{binVsItemAction.selectedBin}"
var="_entity" sourceCaptionLabel="Available Bin List" listsHeight="300px" sourceListWidth="300" targetListWidth="300"
targetCaptionLabel="Selected Bin List" fastOrderControlsVisible="false" oncopyclick="listShuttleAdd()"
sourceSelection="#{binVsItemAction.sourseBinSet}" orderControlsVisible="false" fastMoveControlsVisible="false"
copyControlLabel="Add" switchByDblClick="false" converter="#{binVsItemListShuttleConverter}" removeControlLabel="Remove"
onremoveclick="listShuttleDel()" targetSelection="#{binVsItemAction.targetBinSet}">
<rich:column>
<h:outputText value="#{_entity.code}(#{_entity.acWhBusinessPurpose.description}-#{_entity.acTypeWhMaterial.description})"></h:outputText>
</rich:column>
</rich:listShuttle>
</h:panelGrid>
<a:jsFunction action="#{binVsItemAction.checkSelect()}" name="listShuttleAdd"
reRender="binNoPanel,statusMessages,bottomMessagePanelGrid">
</a:jsFunction>
<a:jsFunction action="#{binVsItemAction.checkDel()}" name="listShuttleDel"
reRender="binNoPanel,statusMessages,bottomMessagePanelGrid">
</a:jsFunction>
</a:region>
</rich:panel>
目标list:sourceValue,对象list::targetValue,主要技术在converter转换器;
package com.acer.agbs.global.item.binvsitemmapping;
import java.io.Serializable;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import com.acer.agbs.model.AcTypeWhMaterial;
import com.acer.agbs.model.AcWhBusinessPurpose;
@BypassInterceptors
@org.jboss.seam.annotations.faces.Converter(id = "binVsItemListShuttleConverter")
@Name("binVsItemListShuttleConverter")
@Scope(ScopeType.CONVERSATION)
public class BinVsItemListShuttleConverter
implements javax.faces.convert.Converter, Serializable {
/**
* shuttleConverter for MdBinItemMapping
*
* @author
*/
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
private BinVsItemAction binVsItemAction;
public Object getAsObject(FacesContext context, UIComponent component, String value) {
String[] temp = value.split(":");
BinHelper bin = new BinHelper();
bin.setAcWhBusinessPurpose(new AcWhBusinessPurpose());
bin.setAcTypeWhMaterial(new AcTypeWhMaterial());
bin.setAid(temp[0]);
bin.setCode(temp[1]);
bin.getAcWhBusinessPurpose().setDescription(temp[2]);
bin.getAcTypeWhMaterial().setDescription(temp[3]);
return bin;
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
BinHelper bin = (BinHelper) value;
return bin.getAid() + ":" + bin.getCode() + ":" + bin.getAcWhBusinessPurpose().getDescription() + ":"
+ bin.getAcTypeWhMaterial().getDescription();
}
}
<java>
public void checkSelect() {
logger.debug("size:" + selectedBin.size());
List<MdBin> list1 = new ArrayList<MdBin>();
list1.addAll(sourseBinSet);
if (list1.size() > 1) {
for (int i = 0; i < list1.size(); i++) {
for (int j = i + 1; j < list1.size(); j++) {
if (list1.get(i).getAcWhBusinessPurpose().getDescription().equals(
list1.get(j).getAcWhBusinessPurpose().getDescription())
&& list1.get(i).getAcTypeWhMaterial().getDescription().equals(
list1.get(j).getAcTypeWhMaterial().getDescription())) {
statusMessages
.add(Severity.ERROR,
"It's not allowed to have different BIN and they have the same business purpose and material type!");
return;
}
}
}
}
Iterator<MdBin> it = sourseBinSet.iterator();
while (it.hasNext()) {
MdBin bin2 = it.next();
BinHelper helper = new BinHelper();
helper.setAcWhBusinessPurpose(new AcWhBusinessPurpose());
helper.setAcTypeWhMaterial(new AcTypeWhMaterial());
helper.setAid(bin2.getAid());
helper.setCode(bin2.getCode());
helper.getAcWhBusinessPurpose().setDescription(bin2.getAcWhBusinessPurpose().getDescription());
helper.getAcTypeWhMaterial().setDescription(bin2.getAcTypeWhMaterial().getDescription());
logger.debug("helper=" + bin2.getAcWhBusinessPurpose().getDescription());
logger.debug("helper=" + helper.getAcWhBusinessPurpose().getDescription());
selectedBin.add(helper);
for (int i = 0; i < availableBin.size(); i++) {
MdBin bin1 = availableBin.get(i);
if (bin1.getAcWhBusinessPurpose().getDescription().equals(bin2.getAcWhBusinessPurpose().getDescription())
&& bin1.getAcTypeWhMaterial().getDescription().equals(bin2.getAcTypeWhMaterial().getDescription())) {
availableBin.remove(bin1);
i = i - 1;
}
}
try {
if (getService().saveBinItemmapping(this.searchVO.getMdItemAttribute().getMdCompany(),
this.searchVO.getMdItemAttribute().getMdItem(), this.searchVO.getMdWarehouseLocation(), bin2)) {
statusMessages.add(Severity.INFO, service.getMessage().poll());
} else {
statusMessages.add(Severity.WARN, service.getMessage().poll());
}
} catch (Exception e) {
e.printStackTrace();
statusMessages.add(Severity.ERROR, e.getMessage());
}
}
}
</java>