I think I found the problem, although I'm not 100% sure. I deleted the data
which populated the selected property of the palette component and then
added the data back into the database. The problem has disappeared.

The strange thing is I couldn't see anything wrong with the original data.

On 10 July 2012 09:47, Jabbar <aja...@gmail.com> wrote:

> Hello all,
>
> I've just spent too long trying to track down a null pointer exception I'm
> having in the Palette component. The partial stack trace I keep getting is
>
> [ERROR] pages.RepairPage Render queue error in
> org.apache.tapestry5.internal.structure.RenderPhaseEventHandler$1@222b37:
> java.lang.NullPointerException
> java.lang.NullPointerException
> at
> org.apache.tapestry5.internal.util.SelectModelRenderer.option(SelectModelRenderer.java:49)
> at
> org.apache.tapestry5.corelib.components.Palette$SelectedRenderer.render(Palette.java:165)
>  at
> org.apache.tapestry5.internal.structure.RenderPhaseEventHandler$1.render(RenderPhaseEventHandler.java:96)
> at
> org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:72)
>  at
> org.apache.tapestry5.internal.services.PageRenderQueueImpl.render(PageRenderQueueImpl.java:124)
> at
> org.apache.tapestry5.internal.services.PageRenderQueueImpl$1.renderMarkup(PageRenderQueueImpl.java:142)
>  at
> org.apache.tapestry5.internal.services.RenderCommandComponentEventResultProcessor.renderMarkup(RenderCommandComponentEventResultProcessor.java:78)
>  at
> org.apache.tapestry5.internal.services.PageRenderQueueImpl$Bridge.renderMarkup(PageRenderQueueImpl.java:62)
> at
> org.apache.tapestry5.internal.services.PageRenderQueueImpl.renderPartial(PageRenderQueueImpl.java:159)
>
> <snip/>
>
> I've seen references to earlier posts in the mailing list where the equals
> and hash methods were not correctly specified, hence I've asked Eclipse to
> autogenerate these methods.
>
> I've included the relevant code in this email and have tried to keep it to
> a minimum but relevant.
>
> Has anybody had this issue before and if so how did you resolve it?
>
> My .tml code excerpt is
>
> <t:palette t:id="repairParts" encoder="repairPartEncoder"
> model="repairPartModel" selected="repairParts"/>
>
> My page class excerpt is
>
>         @Persist
> @Property
> private List<RepairPart> repairParts;
>  @SetupRender
> public void init(){
>  if (repairParts == null)
> repairParts = new ArrayList<RepairPart>();
>  if (actions == null)
> actions = new ArrayList<Actions>();
>  if (faults == null){
> faults = new ArrayList<Faults>();
>  }
> }
>  public ValueEncoder<RepairPart> getRepairPartEncoder(){
> List<RepairPart> parts = createInstance(getRepairPartList());
>  ValueEncoder<RepairPart> encoder = new RepairPartEncoder(parts);
> return encoder;
>  }
>  public SelectModel getRepairPartModel(){
>  return new RepairPartSelectModel(createInstance(getRepairPartList()));
> }
>
>     private  List<RepairPart> createInstance(List<RepairPart> list){
>     List<RepairPart> newList = new ArrayList<RepairPart>();
>
>     for (RepairPart r : list){
>     newList.add(new RepairPart(r));
>     }
>
>     return newList;
>     }
>
>
> Other classes are RepairPart.java, RepairPartEncoder.java,
> RepairPartOptionModel.java, RepairPartSelectModel.java
>
> RepairPart.java
> ----------------------
>
>         @Entity
> public class RepairPart implements Serializable {
>
> <snip/>
>                 @Override public int hashCode() { final int prime = 31;
> int result = 1; result = prime * result + ((cost == null) ? 0 :
> cost.hashCode()); result = prime * result + ((description == null) ? 0 :
> description.hashCode()); result = prime * result + ((id == null) ? 0 :
> id.hashCode()); result = prime * result + ((name == null) ? 0 :
> name.hashCode()); result = prime * result + ((stockCode == null) ? 0 :
> stockCode.hashCode()); return result; } @Override public boolean
> equals(Object obj) { if (this == obj) return true; if (obj == null) return
> false; if (getClass() != obj.getClass()) return false; RepairPart other =
> (RepairPart) obj; if (cost == null) { if (other.cost != null) return false;
> } else if (!cost.equals(other.cost)) return false; if (description == null)
> { if (other.description != null) return false; } else if
> (!description.equals(other.description)) return false; if (id == null) { if
> (other.id != null) return false; } else if (!id.equals(other.id)) return
> false; if (name == null) { if (other.name != null) return false; } else
> if (!name.equals(other.name)) return false; if (stockCode == null) { if
> (other.stockCode != null) return false; } else if
> (!stockCode.equals(other.stockCode)) return false; return true; }
>  }
>
> RepairPartEncoder.java
> ----------------------------------
>
> public class RepairPartEncoder implements ValueEncoder<RepairPart> {
>
> private List<RepairPart> repairPartList = new ArrayList<RepairPart>();
>  public RepairPartEncoder(List<RepairPart> repairPartlist){
> this.repairPartList = repairPartlist;
>  }
>  @Override
>  public String toClient(RepairPart value) {
> return value.getName().trim();
>  }
>
> @Override
> public RepairPart toValue(String clientValue) {
>  for (RepairPart rp : repairPartList){
> if (rp.getName().equals(clientValue))
>  return rp;
> }
>  return null;
> }
> }
>
> RepairPartOptionModel.java
> ----------------------------------------
>
> public class RepairPartOptionModel implements OptionModel {
>
> private RepairPart repairPart;
> private int maxCodeSize;
> `
>  public RepairPartOptionModel(RepairPart repairPart, int maxCodeSize){
> //this.repairPart = repairPart;
>  this.repairPart = new RepairPart(repairPart);
> if (this.repairPart.getStockCode()==null)
>  this.repairPart.setStockCode("");
> this.maxCodeSize = maxCodeSize;
>  if (repairPart.getName()==null)
> repairPart.setName("");
>  if (repairPart.getDescription()==null)
> repairPart.setDescription("");
>  if (repairPart.getStockCode()==null)
> repairPart.setStockCode("");
>  }
>  @Override
>  public String getLabel() {
> return "("+repairPart.getName()+") "+repairPart.getDescription() + " -
> "+repairPart.getStockCode();
>  }
>
> @Override
> public boolean isDisabled() {
>  return false;
> }
>
> @Override
>  public Map<String, String> getAttributes() {
> return new HashMap<String,String>();
>  }
>
> @Override
> public Object getValue() {
>  return repairPart;
> }
> }
>
> RepairPartSelectModel.java
> ----------------------------------------
>
> public class RepairPartSelectModel extends AbstractSelectModel {
>
>  private List<RepairPart> repairPartList;
>  public RepairPartSelectModel(List<RepairPart> repairPartList ){
>  this.repairPartList = repairPartList;
> }
>  @Override
> public List<OptionGroupModel> getOptionGroups() {
> return new ArrayList<OptionGroupModel>();
>  }
>
> @Override
> public List<OptionModel> getOptions() {
>  List<OptionModel> optionModel = new ArrayList<OptionModel>();
> int maxCodeSize = 0;
>  for (RepairPart repairPart : repairPartList){
> if (repairPart.getName().length()>maxCodeSize)
>  maxCodeSize = repairPart.getName().length();
> }
>  for (RepairPart repairPart : repairPartList){
> optionModel.add(new RepairPartOptionModel(repairPart, maxCodeSize));
>  }
>  return optionModel;
>  }
> }
>
>
> --
> Thanks
>
>  A Jabbar Azam
>
>


-- 
Thanks

 A Jabbar Azam

Reply via email to