I have below code need to change it to wicket 6.6, but isTransparentResolver() is removed and I am trying according to this link
https://www.mail-archive.com/commits#wicket.apache.org/msg17546.html
but no use, anybody have solution for below code?
add(new WebMarkupContainer("bodyElement") {
#Override
public boolean isTransparentResolver() {
return true;
}
#Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
if ((usrLoginHstryList == null || usrLoginHstryList.isEmpty()) &&
(usrChangeHstryList == null || usrChangeHstryList.isEmpty())) {
tag.put("onload", "hideHistoryButtons();");
} else if (usrLoginHstryList == null || usrLoginHstryList.isEmpty()) {
tag.put("onload", "hideUserLoginHstryBtn();");
} else if (usrChangeHstryList == null || usrChangeHstryList.isEmpty()) {
tag.put("onload", "hideUserChngHstryBtn();");
}
}
});
Finally I have written this using TransparentWebMarkupContainer
add(new TransparentWebMarkupContainer("bodyElement"){
#Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
if((usrLoginHstryList == null || usrLoginHstryList.isEmpty()) && (usrChangeHstryList == null || usrChangeHstryList.isEmpty())){
tag.put("onload", "hideHistoryButtons();");
}else if(usrLoginHstryList == null || usrLoginHstryList.isEmpty()){
tag.put("onload", "hideUserLoginHstryBtn();");
}else if(usrChangeHstryList == null ||usrChangeHstryList.isEmpty()){
tag.put("onload", "hideUserChngHstryBtn();");
}
}
});
Related
I have to sort items of a class created with #freezed annotation. I have added Comparable interface to the signature. It is causing following compile time exception:
Error (Xcode): lib/models/app_language.freezed.dart:143:7: Error: The
non-abstract class '_$_AppLanguage' is missing implementations for
these members:
Could not build the application for the simulator.
// app_language.dart
import 'package:freezed_annotation/freezed_annotation.dart';
part 'app_language.freezed.dart';
part 'app_language.g.dart';
#freezed
class AppLanguage with _$AppLanguage implements Comparable<AppLanguage> {
const factory AppLanguage({
#Default("en") String id,
String? name,
String? msg,
#Default([0, 0, 0, 0]) List<int> color,
#Default(false) bool rtl,
}) = _AppLanguage;
factory AppLanguage.fromJson(Map<String, dynamic> json) =>
_$AppLanguageFromJson(json);
#override
int compareTo(AppLanguage other) {
if (rtl == other.rtl) {
if (name != null && other.name != null) {
return name!.compareTo(other.name!);
} else if (name == null && other.name == null) {
return 0;
} else if (name != null) {
return 1;
} else {
return -1;
}
} else {
return rtl ? 1 : -1;
}
}
}
pubspec.yaml (snippet)
dependencies:
freezed: ^2.3.2
freezed_annotation: ^2.2.0
dev_dependencies:
build_runner: ^2.3.3
json_serializable: ^6.6.0
usage
// here value is list of AppLanguages and I am returning another sorted list.
return <AppLanguage>[...value]..sort();
How do I resolve compilation error? Any help will be appreciated.
Right now,
I have added separate comparator so that it could work. But having the model class implements the Comparable is desired.
import 'package:freezed_annotation/freezed_annotation.dart';
import '../localization/localization.dart';
part 'app_language.freezed.dart';
part 'app_language.g.dart';
#freezed
class AppLanguage with _$AppLanguage {
const factory AppLanguage({
#Default(localeDefault) String id,
String? name,
String? msg,
#Default([0, 0, 0, 0]) List<int> color,
#Default(false) bool rtl,
}) = _AppLanguage;
factory AppLanguage.fromJson(Map<String, dynamic> json) =>
_$AppLanguageFromJson(json);
// #override
// // ignore: library_private_types_in_public_api
// int compareTo(_$_AppLanguage other) {
// if (rtl == other.rtl) {
// if (name != null && other.name != null) {
// return name!.compareTo(other.name!);
// } else if (name == null && other.name == null) {
// return 0;
// } else if (name != null) {
// return 1;
// } else {
// return -1;
// }
// } else {
// return rtl ? 1 : -1;
// }
// }
}
int appLanguageComparator(AppLanguage a, AppLanguage b) {
if (a.rtl == b.rtl) {
final aName = a.name;
final bName = b.name;
if (aName != null && bName != null) {
return aName.compareTo(bName);
} else if (aName == null && bName == null) {
return 0;
} else if (aName != null) {
return 1;
} else {
return -1;
}
} else {
return a.rtl ? 1 : -1;
}
}
Usage:
return <AppLanguage>[...value]..sort(appLanguageComparator);
For others that will encounter the same issue in the future, in order to add custom methods/getters etc to a freezed class you need to provide a empty const constructor. For example:
#freezed
class Person with _$Person {
const factory Person(String name, {int? age}) = _Person;
void method() {
print('hello world');
}
}
This implementation will throw a compile error and in order to make it work you need to do:
#freezed
class Person with _$Person {
// Added constructor. Must not have any parameter
const Person._();
const factory Person(String name, {int? age}) = _Person;
void method() {
print('hello world');
}
}
Keep in mind, the constructor must be an empty constructor.
You have to extend the class with Comparable<AppLanguage> and should override compareTo with parameter of AppLanguage as following
import 'package:freezed_annotation/freezed_annotation.dart';
import '../localization/localization.dart';
part 'app_language.freezed.dart';
part 'app_language.g.dart';
#freezed
class AppLanguage extends Comparable<AppLanguage> with _$AppLanguage {
const factory AppLanguage({
#Default(localeDefault) String id,
String? name,
String? msg,
#Default([0, 0, 0, 0]) List<int> color,
#Default(false) bool rtl,
}) = _AppLanguage;
factory AppLanguage.fromJson(Map<String, dynamic> json) =>
_$AppLanguageFromJson(json);
#override
int compareTo(AppLanguage other) {
if (rtl == other.rtl) {
if (name != null && other.name != null) {
return name!.compareTo(other.name!);
} else if (name == null && other.name == null) {
return 0;
} else if (name != null) {
return 1;
} else {
return -1;
}
} else {
return rtl ? 1 : -1;
}
}
}
I'd like to have a function that checks to see if any of the text edit controller fields are null.
I wrote this method below, but I wanted to see if there was a more elegant solution.
bool _nullfieldExists(){
//return a true if any of the textEditController fields are null
if (_textEditControllerNumberPlayers.text == null ){
return true;
}
else if (_textEditControllerSmallBlind.text == null ){
return true;
}
else if (_textEditControllerBigBlind.text == null ){
return true;
}
else if (_textEditControllerAnte.text == null ){
return true;
}
else if (_textEditControllerMyStack.text == null ){
return true;
}
else {
return false;
}
}
I need translate a Java code to Scala, but the compiler show me error. I understand that parameter input on methods are val type. Which alternative i can adopt if i need transform these values? I think to apply case class or class... Below the snippet code (in Scala):
def pmerge_FA(x: Pennant,y: Pennant): Pennant={
if(x == null && y == null && this.root == null){
return null
}else if(x == null && y == null){
return this
}else if(this.root == null && x == null){
return y
}else if(this.root == null && y == null){
return x
}else if(x == null){
y = y.pmerge(this) //error
null
}else if(this.root == null){
y = y.pmerge(x) //error
null
}else if (y == null){
y = this.pmerge(x) // error
null
}else{
y = y.pmerge(x)
this
}
}
Note that error is showed where y parameter is updated.
Thanks
Yes, the error is shown because you cannot reassign something to val, and parameters to methods in Scala are only sent as vals (immutables).
Because you don't provide the full definition of this, it's difficult to suggest an alternative solution, but:
In general, instead of if-else "Java" style, in Scala you can use pattern matching, and instead of null you can use Option, which is very powerful.
For Example, I suggest refactoring your method in this "Scala" Style (partial implementation)
def pmerge_FA(x: Pennant, y: Pennant): Option[Pennant] = {
(Option(x),Option(y), Option(this.root)) match {
case (None, None, None) => None
case (None, None, _) => Option("")
case (None, _, None) => Option(y)
case (_, None, None) => Option(x)
case (None, _, _) =>
....
}
}
Such that you will return the x, y as their new values, or create a case class like:
case class PennantCaseClass (x:Pennant, y:Pennant)
And returning it when needed.
Again, If you will provide some more info about Pennant class it will be easier to give a better alternative implementation for this method.
New values of y (namely y.pmerge(...)) are never used after assignments. So I guess all assignments y = y.pmerge(...) can be replaced with just invocations y.pmerge(...).
Does y.pmerge(...) do any side effects? Just in case, if not then values y.pmerge(...) are never used (only null or this is returned), so in such case lines y = y.pmerge(...) can be removed at all.
So the code can be either (if there are side effects)
def pmerge_FA(x: Pennant,y: Pennant): Pennant={
if(x == null && y == null && this.root == null){
null
}else if(x == null && y == null){
this
}else if(this.root == null && x == null){
y
}else if(this.root == null && y == null){
x
}else if(x == null){
y.pmerge(this)
null
}else if(this.root == null){
y.pmerge(x)
null
}else if (y == null){
this.pmerge(x)
null
}else{
y.pmerge(x)
this
}
}
or (if there are no side effects)
def pmerge_FA(x: Pennant,y: Pennant): Pennant={
if(x == null && y == null && this.root == null){
null
}else if(x == null && y == null){
this
}else if(this.root == null && x == null){
y
}else if(this.root == null && y == null){
x
}else if(x == null){
null
}else if(this.root == null){
null
}else if (y == null){
null
}else{
this
}
}
Oh, right! There are three classes to build a Bag data structure object, with nodes added in perfectly balanced tree. These methods works in that one. Below the complete code (in Java). The Pennant class build a forest using the node of graph object.
Node Class:
public class Node {
private Node left;
private Node right;
private int item;
public Node() {
left = null;
right = null;
item = 0;
}
public Node(int value) {
left = null;
right = null;
item = value;
}
public Node getLeft() {
return left;
}
public void setLeft(Node left) {
this.left = left;
}
public Node getRight() {
return right;
}
public void setRight(Node right) {
this.right = right;
}
public int getItem() {
return this.item;
}
public void setItem(int item) {
this.item = item;
}
}
public class Pennant{
private Node root;
public Pennant() {
this.root = null;
}
public Pennant(int value) {
this.root = new Node(value);
}
public void setRoot(Node root) {
this.root = root;
}
public Node getRoot() {
return this.root;
}
public Pennant pmerge(Pennant y) {
if(this.getRoot() == null) {
return y;
}else {
this.getRoot().setRight(y.getRoot().getLeft());
y.getRoot().setLeft(this.getRoot());
}
return y;
}
public Pennant pmerge_FA(Pennant x, Pennant y) {
if(x == null && y == null && this.getRoot() == null) {
return null;
}else if(x == null && y == null) {
return this;
}else if(this.getRoot() == null && x == null) {
return y;
}else if(this.getRoot() == null && y == null) {
return x;
}else if(x == null) {
y = y.pmerge(this);
return null;
}else if(this.getRoot() == null) {
y = y.pmerge(x);
return null;
}else if (y == null) {
y = this.pmerge(x);
return null;
}else {
y = y.pmerge(x);
return this;
}
}
public Pennant psplit() {
if(this.getRoot() != null && this.getRoot().getLeft() != null) {
Pennant y = new Pennant();
y.setRoot(this.getRoot().getLeft());
this.getRoot().setLeft(y.getRoot().getRight());
y.getRoot().setRight(null);
return y;
}
return null;
}
public void remove_all(Node node) {
if (node.getLeft() != null) {
remove_all(node.getLeft());
}
if(node.getRight() != null) {
remove_all(node.getRight());
}
node = null;
}
}
I study the mybatis3.3 sources code and now I have a question:in the XMLMapperBuilder.databaseIdMatchesCurrent()
private boolean databaseIdMatchesCurrent(String id, String databaseId, String requiredDatabaseId) {
if (requiredDatabaseId != null) {
if (!requiredDatabaseId.equals(databaseId)) {
return false;
}
} else {
if (databaseId != null) {
return false;
}
// skip this fragment if there is a previous one with a not null databaseId
if (this.sqlFragments.containsKey(id)) {
XNode context = this.sqlFragments.get(id);
if (context.getStringAttribute("databaseId") != null) {
return false;
}
}
}
return true;
}
if the (requiredDatabaseId == null && databaseId != null) ,then the function will return false.
So the code
if (this.sqlFragments.containsKey(id)) {
XNode context = this.sqlFragments.get(id);
if (context.getStringAttribute("databaseId") != null) {
return false;
}
}
certainly no way to return false and this code is useless.
I just want to questioning: I understand this, right?
I have two elements, adult no and children no, at least one field is required. How to validate this in zend framework and generate error message.
You need to create Your own validator. In this case i think You could use Zend_Validate_Identical, copy its code and change isValid method to something like this:
public function isValid($value, $context = null)
{
$this->_setValue((string) $value);
if (($context !== null) && isset($context) && array_key_exists($this->getToken(), $context)) {
$token = $context[$this->getToken()];
} else {
$token = $this->getToken();
}
if ($token === null) {
$this->_error(self::MISSING_TOKEN);
return false;
}
$strict = $this->getStrict();
// change != to ==
if (($strict && ($value === $token)) || (!$strict && ($value == $token)) && (&token =='' || $value == '') {
$this->_error(self::**YOUR_ERROR _CODE**);
return false;
}
return true;
}
This code is not tested but it should work :)